package cn.steel.service.impl;

import cn.steel.domain.entity.InventoryAnalysis;
import cn.steel.domain.entity.PriceTrendAnalysis;
import cn.steel.domain.entity.ProductCategory;
import cn.steel.mapper.DashboardMapper;
import cn.steel.mapper.ProductCategoryMapper;
import cn.steel.service.DashboardService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

@Service
@RequiredArgsConstructor
public class DashboardServiceImpl implements DashboardService {
    private final DashboardMapper dashboardMapper;
    private final ProductCategoryMapper categoryMapper;

    @Override
    public Map<String, List<InventoryAnalysis>> getInventoryDataGroupedByCategory() {
        Map<String, List<InventoryAnalysis>> result = new LinkedHashMap<>();
        List<ProductCategory> categories = categoryMapper.findAllCategories();
        for (ProductCategory category : categories) {
            List<InventoryAnalysis> list = dashboardMapper.findByCategoryId(category.getId());
            result.put(category.getName(), list);
        }
        return result;
    }

    @Override
    public List<InventoryAnalysis> getInventoryDataByCategoryAndRegion(Long categoryId) {
        return dashboardMapper.findInventoryByCategoryAndRegion(categoryId);
    }

    @Override
    public List<PriceTrendAnalysis> getPriceTrendsByCategory(Long categoryId) {
        return dashboardMapper.findPriceTrendsByCategory(categoryId);
    }


}